﻿Imports Microsoft.VisualBasic
Imports ACompany.OrderProcessing.Infrastructure
Imports ACompany.OrderProcessing.NhibernateRepository
Imports ACompany.OrderProcessing.Services
Imports ACompany.OrderProcessing.Model
Imports StructureMap
Imports StructureMap.Pipeline
Imports StructureMap.Configuration

Public Class BootStrapper

    Public Shared Sub ConfigureStructureMap()
        ObjectFactory.Initialize(AddressOf ConfigStructureMap)
    End Sub

    Private Shared Sub ConfigStructureMap(ByVal x As IInitializationExpression)
        x.AddRegistry(New ServiceRegistry)
    End Sub

    Public Class ServiceRegistry
        Inherits StructureMap.Configuration.DSL.Registry

        Protected Overloads Overrides Sub configure()

            ForRequestedType(Of IProductRepository)() _
                .TheDefaultIsConcreteType(Of ProductRepository)()

            ForRequestedType(Of IOrderRepository)() _
               .TheDefaultIsConcreteType(Of OrderRepository)()

            ForRequestedType(Of ICustomerRepository)() _
               .TheDefaultIsConcreteType(Of CustomerRepository)()

            ForRequestedType(Of ICustomerService)() _
               .TheDefaultIsConcreteType(Of CustomerService)()

            ForRequestedType(Of IProductService)() _
               .TheDefaultIsConcreteType(Of ProductService)()

            ForRequestedType(Of IOrderService)() _
               .TheDefaultIsConcreteType(Of OrderService)()

            ForRequestedType(Of IUnitOfWork)() _
               .TheDefaultIsConcreteType(Of NhibernateUnitOfWork)()
        End Sub
    End Class
End Class
